package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSetmealController")
@RequestMapping("admin/setmeal")
@Slf4j
@Api(tags = "管理端套餐模块")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 分页查询套餐
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public Result<PageResult>selectPage(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("管理端套餐分页查询:{}",setmealPageQueryDTO);
        PageResult pageResult=setmealService.selectPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 新增套餐
     * @return
     */
    @PostMapping
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("管理端新增套餐:{}",setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }


    /**
     * 起售或停售套餐
     */
    @ApiOperation("起售或停售套餐")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("套餐{}被{}",id,status== StatusConstant.ENABLE?"启售":"停售");
        setmealService.startOrStop(id,status);
        return Result.success();
    }


    /**
     * 根据套餐id查询套餐
     * @return
     */
    @ApiOperation("根据套餐id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO>selectById(@PathVariable Long id){
        log.info("根据套餐id{}查询套餐",id);
        SetmealVO setmealVO=setmealService.selectById(id);
        return Result.success(setmealVO);
    }


    /**
     * 修改套餐
     * @return
     */
    @ApiOperation("修改套餐")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐:{}",setmealDTO);
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }


    /**
     * 批量删除套餐
     * @return
     */
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result deleteBatch(@RequestParam List<Long>ids){
        log.info("批量删除套餐:{}",ids);
        setmealService.deleteBatch(ids);
        return Result.success();
    }

}
